﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using SmallBusinessKit.DataAccess.Interfaces;
using SmallBusinessKit.Domains;
using SmallBusinessKit.Interfaces;
using SmallBusinessKit.Models.Entities;

namespace SmallBusinessKit.Tests.Domains
{
    /// <summary>
    /// Unit Tests for TestimonialDomain Logic
    /// </summary>
    /// /// <remarks>These tests don't really test anything ~ lol</remarks>
    [TestClass]
    public class CatelogDomainTests : UnitTestBase
    { 
        #region Properties

        private Mock<ICategoryRepository>   _moqCategoryRepository;
        private Mock<IItemRepository>       _moqItemRepository;
        private ICatalogDomain _domain;

        #endregion Properties

        #region Tests

        [TestInitialize]
        public override void Setup()
        {
            base.Setup();

            _moqCategoryRepository  = new Mock<ICategoryRepository>();
            _moqItemRepository      = new Mock<IItemRepository>();

            var categories          = XmlData.ParseCategories();
            var category            = categories.FirstOrDefault(i => i.Id == "c11");
            var items               = XmlData.ParseItems();

            var selectedCategories = categories.Where(i => i.ParentId == null && i.IsVisible).ToList();
            _moqCategoryRepository.Setup(m => m.GetMany(It.IsAny<Expression<Func<Category, bool>>>())).Returns(selectedCategories);
            _moqCategoryRepository.Setup(m => m.Get(It.IsAny<Expression<Func<Category, bool>>>())).Returns(category);
            _moqItemRepository.Setup(m => m.Get(It.IsAny<Expression<Func<Item, bool>>>())).Returns(items.FirstOrDefault(i => i.Id == "02"));

            _domain = new CatalogDomain(_moqCategoryRepository.Object, _moqItemRepository.Object);
        }

        [TestMethod]
        public void GetCategories()
        {
            // Act
            var results = _domain.GetCategories(null);

            // Assert
            Assert.IsNotNull(results);
            Assert.IsInstanceOfType(results, typeof(IEnumerable<Category>));
            Assert.AreEqual(5, results.Count());
        }

        [TestMethod]
        public void GetChildItems()
        {
            // Act
            var results = _domain.GetChildItems("c11");

            // Assert
            Assert.IsNotNull(results);
            Assert.IsInstanceOfType(results, typeof(IEnumerable<Item>));
            Assert.AreEqual(3, results.Count());
        }

        [TestMethod]
        public void GetItem()
        {
            // Act
            var result = _domain.GetItem("02");

            // Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(Item));
            Assert.AreEqual("02",result.Id);
        }

        #endregion
    }
}
